<template>
  <div class="collection">
    <div class="label-name">我的收藏</div>
    <div class="collection-all">
      <ul>
        <li v-for="(item, index) in colleList" :key="index">
          <div class="collection-item">
            <div class="collection-img">
              <img :src="item.giBackdrop" alt="" @click="goGame(item.giId)" />
            </div>

            <div class="collection-bottom">
              <div>
                <span @click="goGame(item.giId)">{{ item.giName }}</span>
              </div>
              <div>
                收藏于 : <span>{{ item.cgTime }}</span>
              </div>
            </div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { userCollection } from "../../../network/usermes";

export default {
  name: "Collection",
  data() {
    return {
      colleList: [],
      pages: 1,
      page: "",
    };
  },
  created() {
    this.getCollection();
  },
  mounted() {
    window.addEventListener("scroll", this.scrollNav);
  },

  methods: {
    getCollection() {
      userCollection(this.pages, this.$Cookie.get("userid")).then((res) => {
        console.log(res);
        this.page = res.data.data.pages;
        if (this.pages > this.page) {
          console.log(this.pages);
        } else {
          this.pages += 1;
          this.colleList.push(...res.data.data.list);
        }
      });
    },

    scrollNav() {
      let bottom =
        document.documentElement.scrollHeight -
        document.documentElement.scrollTop -
        document.documentElement.clientHeight;
      if (bottom < 150 && this.pages <= this.page) {
        this.getCollection();
      }
    },

    goGame(id) {
      this.$router.push({ name: "详情", params: { id: id } });
    },
  },
};
</script>

<style>
.collection {
  width: 80%;
  margin: 0 auto;
}

.label-name {
  font-size: 0.15rem;
  margin-top: 0.25rem;
  border-bottom: 1px solid rgb(187, 185, 184);
  padding-bottom: 0.1rem;
}

.collection-all ul {
  list-style: none;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 0.7rem;
}

.collection-all ul li {
  width: 25%;
  margin-top: 0.3rem;
}

.collection-item {
  width: 90%;
}

.collection-img {
  width: 100%;
  height: 0.9rem;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
}

.collection-item img {
  width: 100%;
  height: 0.9rem;
  border-radius: 10px;
  transition: all 0.5s;
}

.collection-item img:hover {
  transform: scale(1.1);
}

.collection-bottom div:nth-child(1) {
  margin-top: 0.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.collection-bottom div:nth-child(1) span {
  font-size: 0.1rem;
  cursor: pointer;
}

.collection-bottom div:nth-child(1) span:hover {
  color: rgb(36, 184, 242);
}

.collection-bottom div:nth-child(2) {
  font-size: 0.08rem;
  color: rgb(160, 161, 161);
  margin-top: 0.05rem;
}
</style>